/*
 * Copyright (c) 2023 fred
 * Licensed under the Apache License,Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
import { Connection } from './Connection';
import { HttpConnection } from './helper/HttpConnection';
import { Document } from './nodes/Document';
import { Parser } from './parser/Parser';

/**
 * The core public access point to the jsoup functionality.
 *
 * @author Jonathan Hedley
 */
export class Jsoup {
  private constructor() {
  }

  /**
   * Parse HTML into a Document, using the provided Parser. You can provide an alternate parser, such as a simple XML
   * (non-HTML) parser.
   *
   * @param html    HTML to parse
   * @param baseUri The URL where the HTML was retrieved from. Used to resolve relative URLs to absolute URLs, that occur
   *                before the HTML declares a {@code <base href>} tag.
   * @param parser  alternate {@link Parser#xmlParser() parser} to use.
   * @return sane HTML
   */
  public static parse(html:string, baseUri?:string |null, parser?:Parser |null):Document {
    baseUri = (baseUri === undefined || baseUri === null) ? "":baseUri
    if (parser !== undefined && parser !== null) {
      return parser.parseInput(html,baseUri)
    } else {
      return Parser.parse(html,baseUri)
    }
  }


  public static newSession(): Connection {
    return new HttpConnection();
  }
}
